package com.door.erp.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.door.erp.dwz.DwzResponse;
import com.door.erp.model.OutputOrder;
import com.door.erp.model.OutputStatus;
import com.door.erp.pager.Pager;
import com.door.erp.sevice.OutputOrderService;

@Controller
public class OutputOrderController {
	
	@Resource(name="outputOrderService", type=OutputOrderService.class)
	private OutputOrderService outputOrderService;
	
	@RequestMapping("/outputorder/outputorders.do")
	public String getOutputOrders(HttpServletRequest request, Pager pager) {
		if(pager == null) {
			pager = new Pager();
		}
		int totalCount = outputOrderService.getCount();
		pager.setTotalCount(totalCount);
		List<OutputOrder> outputorders = outputOrderService.getAll(pager);
		request.setAttribute("outputorders", outputorders);
		request.setAttribute("pager", pager);
		return "outputorder/outputorders";
	}
	
	@RequestMapping("/outputorder/modify.do")
	public ModelAndView modify(@RequestParam(value="id", required=true) long id, OutputStatus outputStatus) {
		OutputOrder outputOrder = outputOrderService.getObject(id);
		outputOrder.setOutputStatus(outputStatus);
		outputOrderService.modify(outputOrder);
		ModelAndView mav = new ModelAndView("dwzresponse");
		DwzResponse resonse = new DwzResponse();
		resonse.setStatusCode("200");
		resonse.setNavTabId("outputorder");
		resonse.setMessage("修改生产单成功");
		mav.addObject("response", resonse);
		return mav;
	}
	
	@RequestMapping("/outputorder/getOutputOrder.do")
	public ModelAndView getOutputOrder(long id) {
		OutputOrder outputOrder = outputOrderService.getObject(id);
		ModelAndView mav = new ModelAndView();
		mav.setViewName("outputorder/modify");
		mav.addObject("outputorder", outputOrder);
		return mav;
	}
	/*
	@RequestMapping("/outputorder/delete.do")
	public ModelAndView delete(long id) {
		outputOrderService.delete(id);
		ModelAndView mav = new ModelAndView("dwzresponse");
		DwzResponse resonse = new DwzResponse();
		resonse.setStatusCode("200");
		resonse.setMessage("删除成功");
		mav.addObject("response", resonse);
		return mav;
	}
	*/
}
